/**
 * @author Farah
 */

var dogIcon = "img/dog.png";
var timeoutId;

//Constructor for dog object
function dog(config){
	this.position = config.position;
	console.log('dog created '+ this.position.lat());
	
} 


//Places the dogmarker on the map
dog.prototype.showDogOnMap=function(){
	// console.log('inside showDogOnMap');
	displayIconOnMap(dogIcon, this.position);
};

//Moves the dog torandom positions close to home on the map
dog.prototype.unleaseDog=function(){
	console.log('inside unleaseDog');
	//use seTimeout to call moveDogtoNewPosition
};

//Stop the dog from moving 
dog.prototype.leaseDog=function(){
	console.log('inside leaseDog');
	// disable the set timeout
};

//Get dog's current location 
dog.prototype.getDogCurrentPosition=function(){
	//set global variable
	dogPos = this.position;
};

//Moves dog to a new random location 
dog.prototype.moveDogtoNewPosition=function(){
	//TODO :show path of the dog on map 
	//get current position
	var dogCurPos = this.position;
	var dogCurPosLat = dogCurPos.lat();
	var dogCurPosLng = dogCurPos.lng();
	
	
	
	// use math.random to generate a new location
	
	//delete the current marker
	
	//create a new marker in a new position
	
	//set global variable
};


/**
 * Calculates the distance in meters between the dog and specified coordinates.
 * Based on https://developers.google.com/maps/articles/mvcfun#makingitwork.
 */
dog.prototype.distance = function(lat, lng)
{
    var R = 6371;
    var dLat = (this.position.lat() - lat) * Math.PI / 180;
    var dLon = (this.position.lng() - lng) * Math.PI / 180;
    var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
        Math.cos(lat * Math.PI / 180) * Math.cos(this.position.lat() * Math.PI / 180) *
        Math.sin(dLon / 2) * Math.sin(dLon / 2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    var d = R * c;
    return d * 1000;
};


